﻿using Microsoft.AspNetCore.Mvc;
using System.Reflection;
using D.UtilCore;
using CozeDomain.IServices;
using D.UtilCore.Dtos;
using D.UtilCore.Filters;
using Microsoft.AspNetCore.Authorization;
using D.UtilFreesqlOrm;
using CozeDto.ConversationDtos;
using CozeDomain.Services;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Caching.Memory;
using static FreeSql.Internal.GlobalFilter;

namespace CozeWapApi
{
    /// <summary>
    /// 会话历史
    /// </summary>
    [Route("/api/[controller]/[action]")]
    public class ConversationController : BaseApiController
    {

        private readonly IWebHostEnvironment _hostingEnvironment;
        private readonly IConversationService _conversationService;

        /// <summary>
        /// 构造注入
        /// </summary>
        public ConversationController(IWebHostEnvironment hostingEnvironment, IConversationService conversationService)
        {
            _hostingEnvironment = hostingEnvironment;
            _conversationService = conversationService;
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [HttpGet, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<List<RepConversationInfo>>> List()
        {
            return await _conversationService.QueryConversationListAsync(LoginId);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}"), TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> Delete(string id)
        {
            return await _conversationService.DeleteConversationAsync(new List<string> { id });
        }
    }
} 